import { createStore } from "vuex";

export default createStore({
    //Vuex的状态，实际上就是存数据的地方
    state: {
        editableTabs: [], // 存储打开的标签页
        editableTabsValue: '', // 当前激活的标签页
        //页面刷新数据丢失的解决方案
        name: sessionStorage.getItem('u') || ""
    },
    //提供直接操作Vuex的方法，注意mutations里的方法中不能有任何异步操作
    mutations: {
        setname: (state, data) => {
            state.name = data;
            sessionStorage.setItem('u', state.name)
        }, proID: (state, data) => {
            state.proID = data;
        }, proCode: (state, data) => {
            state.proCode = data;
        }, customerCode: (state, data) => {
            state.customerCode = data;
        }, closeTab(state, path) {
            state.editableTabs = state.editableTabs.filter(tab => tab.path !== path);
            // 如果关闭的是当前页，自动切换到相邻标签页
            if (state.editableTabsValue === path) {
                state.editableTabsValue = state.editableTabs[state.editableTabs.length - 1]?.path || '/';
            }
        }, SalesOrderCode: (state, data) => {
            state.SalesOrderCode = data;
        }, SalesOutboundCode: (state, data) => {
            state.SalesOutboundCode = data;
        }, SalesReturnCode: (state, data) => {
            state.SalesReturnCode = data;
        }, FinishedGoodsStoreCode: (state, data) => {
            state.FinishedGoodsStoreCode = data;
        },PO_UpdeteArray:(state, data)=>{
            state.PO_UpdeteArray = data;
        },dict:(state, data)=>{
            state.dict = data;
        },
    }
})